
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑器</title>
    <meta name="renderer" content="webkit"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <!--编辑器加载-->
    <link rel="stylesheet" href="__PUBLIC__/plugins/wangEditor/css/wangEditor.css">
    <!--编辑器加载完毕-->
    <link rel="stylesheet" href="//static.115z.com/layui/css/layui.css" type="text/css" media="all"/>
    <link rel="stylesheet" href="//static.115z.com/css/public.css" type="text/css" media="all"/>
    <style>
        body,html{
            background: #FFF;
            width:100%;
            min-width:100%;
            max-width:100%;
        }

        .wangEditor-menu-container .menu-group {
            padding: 0;
        }

        .wangEditor-container {
            border: 1px solid #e6e6e6;
        }
        .u-tg .atuikeFormSkin1 {
            width:100%!important;
            padding: 20px;
        }

        .u-tg .zipupload {
            padding: 0 35px;
            border: 1px solid #F6F6F6;
        }

        .u-tg .zipupload i {
            vertical-align: middle;
            position: relative;
            margin-right: 4px;
            font-size: 22px;
        }

        .u-tg .beizupload {
            width: calc(100% - 90px - 202.5px - 10px - 45px);
            margin-right: 0;
            padding: 0 !important;
        }

        .u-tg .layui-btn {
            line-height: 42px;
            height: 42px;
            width: 100%;
            padding:0;
        }

        .u-tg .layui-input {
            line-height: 20px;
            height: 42px;
            border: 0;
            border-bottom: 1px solid #F6F6F6 !important;
            border-radius: 0;
            padding: 11px 0;
        }

        .layui-select-title .layui-input {
            border: 1px solid #F6F6F6 !important;
            padding: 0 8px 0 13px;
        }

        .u-tg .layui-form-label {
            padding: 11px 0;
            display: block;
            width: 100%;
        }

        .u-tg .layui-icon-loading {
            width: 53px;
            margin-top: -6px;
        }

        .u-tg .edui-container {
            border: 1px solid #F6F6F6;
            box-shadow: none;
            width: 100% !important;
        }

        .u-tg .edui-container .edui-toolbar {
            border-bottom: 1px solid #F6F6F6;
            box-shadow: none;
        }

        .u-tg .edui-container .edui-btn-toolbar {
            padding: 10px 10px;
        }

        .u-tg #myEditor {
            width: 100% !important;
            padding: 10px !important;
        }

        .u-tg .edui-editor-body .edui-body-container p {
            line-height: 25px;
        }

        .u-tg .title {
            padding-right: 88px;
        }

        .u-tg .title a {
            float: right;
            font-size: 15px;
            color: #a5a5a5;
        }

        .u-tg .edui-scale {
            -webkit-box-sizing: content-box;
            box-sizing: content-box;
        }

        .u-tg .layui-input-block {
            margin-left: 0;
            float: left;
            width: 100%;
        }

        .layui-form-radio > i {
            color: #efefef;
        }

        .layui-form-radio i:hover, .layui-form-radioed i {
            color: #58aaff;
        }

        .fmtup {
            width: 100%;
            text-align: center;
            height: 115px;
            overflow: hidden;
        }

        .fmtup div {
            width: 100%;
            text-align: center;
            height: 115px;
            line-height: 115px;
            font-size: 17px;
            cursor: pointer;
            color: #bdbdbd;
            background: #fdfdfd;
            border: 1px dashed #Ececec;
        }

        .fmtup img {
            width: 100%;
            min-height: 100%;
        }

        ::-webkit-scrollbar {
            width: 2px;
            height: 8px;
        }

        .atuikeLayerSkin1 {
            max-width: 95% !important;
            min-width: 95% !important;
            width: 95% !important;
            left: 50% !important;
            margin-left: -47.5% !important;
        }

        /*重置图片选择器的手机兼容样式*/
        .edui-modal.edui-dialog-image {
            width: 95% !important;
            margin-left: -47.5% !important;
        }

        .edui-modal-body.edui-dialog-image-body {
            width: 100% !important;
            height: 250px !important;
        }

        .edui-image-wrapper {
            height: 100%;
            margin: 0 !important;
            padding: 15px;
        }

        .edui-tab-content > div {
            height: 100%;
        }

        .edui-tab-content {
            height: 100%;
        }

        .edui-dialog-image .edui-image-content {
            height: 100% !important;
        }

        #myEditor img {
            max-width: 100%;
        }

        .edui-tab-nav {
            height: 35px;
            display: none !important;
        }

        .edui-dialog-image .edui-image-item {
            margin: 0 !important;
            width: 48% !important;
            margin-bottom: 13px !important;
        }

        .edui-dialog-image .edui-image-item:nth-child(2n) {
            margin-left: 4% !important;
        }

        .edui-modal.edui-dialog-link {
            width: 95% !important;
            margin-left: -47.5% !important;
        }

        .edui-dialog-link-body {
            width: 100% !important;
        }

        #myEditor {
            width: 100%;
            height: 280px;
        }
    </style>
</head>
<body class="u-tg">
<form class="layui-form atuikeFormSkin1" onsubmit="return false;">
    <div class="layui-form-item">
        <label class="layui-form-label" style="padding-bottom:0;padding-top:20px;">
            投稿标题<font color="#FF0000">*</font>
        </label>
        <div class="layui-input-block">
            <input type="text" class="layui-input"  placeholder="标题" lay-verify="title" name="title"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">投稿内容<font color="#FF0000"> *</font></label>
        <div class="layui-input-block">
            <textarea id="textarea" name="content" required="" lay-verify="required" placeholder="详细描述" class="layui-textarea fly-editor" style="height: 460px;"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">投稿专区</label>
        <div class="layui-input-block">
            <select name="type_id" title="选择分类">
                <option value="">请选择分类</option>
                {volist name="category" id="vo"}
                <option value="{$vo.id}">{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item" style="width: 190px;">
        <label class="layui-form-label">投稿封面</label>
        <div class="layui-input-block">
            <div class="fmtup uploadImg">
                <div>暂未上传</div>
                <img src="" hidden>
                <input type="hidden" name="cover_img">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类　　型</label>
        <div class="layui-input-block">
            <input type="radio" name="type"  value="text" title="纯文章" lay-filter="typeradio" checked>
            <input type="radio" name="type"  value="file" title="有附件" lay-filter="typeradio">
        </div>
    </div>
    <div class="layui-form-item zips" hidden s>
        <label class="layui-form-label">教程附件<font color="#FF0000"> *</font></label>
        <div class="layui-input-block">
            <button type="button"  class="layui-btn layui-btn-primary zipupload"><i class="layui-icon layui-icon-upload-drag"></i> 上传附件
            </button>
            <div class="layui-form-mid layui-word-aux">
                允许上传Zip/Rar/Mp4/Apk类型，限制最大200M
            </div>
        </div>
    </div>


    <!--div class="layui-form-item">
            <div class="layui-input-block"><font color="#ef0048">近期115资源网正在备案，目前服务器是国外线路，带有附件投稿的请先将资源上传到网盘再投稿</font></div>
    </div-->


    <div class="layui-form-item jdt" hidden style="margin-top:-20px;margin-bottom:10px;">
        <div class="layui-input-block">
            <div class="layui-progress">
                <div class="layui-progress-bar" lay-percent="0%"></div>
            </div>
        </div>
    </div>
    <div class="layui-form-item zips" hidden>
        <div class="layui-input-block">
            <input type="text" id="down_link1" name="down_link1" placeholder="可以直接写附件下载路径（或网盘下载地址）"   autocomplete="off"  class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">投稿奖励</label>
        <div class="layui-input-block">
            <input type="checkbox"  lay-skin="switch" title="" lay-filter="payopen" name="is_need">
        </div>
    </div>
    <div class="pays" hidden>

        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input type="text"  name="alipay_name" placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">支付宝账号</label>
            <div class="layui-input-block">
                <input type="text"  name="alipay_account" placeholder="" class="layui-input">
            </div>
        </div>

    </div>
    <div class="layui-form-item" style="margin-bottom:0;">
        <div class="layui-input-block">
            <button class="layui-btn atuikeBtnSkin1"  lay-submit lay-filter="submitAll">立即投稿</button>
        </div>
    </div>
</form>
<script src="//static.115z.com/layui/layui.js"></script>
<script type="text/javascript" src="__PUBLIC__js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugins/wangEditor/js/wangEditor.min.js"></script>

<script type="text/javascript">
    var api = {
        upload: "/index/upload/upfile.html",
        tg: "/user/tg.html"
    };
    var editor = new wangEditor('textarea');
    $.getJSON("{:url('index/index/getemotion')}", function(data) {
        editor.config.uploadImgUrl = '{:url("index/upload/wangeditor_upimage")}';
        editor.config.uploadImgFileName = 'FileName';
        var emotiondata;
        emotiondata = data;
        emotiondata = JSON.parse(emotiondata);
        editor.config.emotions = emotiondata;
        editor.config.menus = ['bold', 'fontsize', 'forecolor', 'link', 'unlink','img', 'fullscreen'];
        editor.config.pasteText = false;
        editor.create();
    });

    layui.use(['form', 'layer', 'upload', 'element'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var upload = layui.upload;
        var element = layui.element;
        //监听提交
        form.on('submit(submitAll)', function (data) {
            // var content = um.getContent();
            var auto_pass = $("input[name=auto_pass]");
            //verifyContent(editINFO);
            // if ($(".layui-input[name='title']").val().length < 2  || (data.field.type === 'text')) {
            //     alt('标题或内容过于简短');
            //     return false;
            // }
            if(!data.field.type_id){
                alt('请选择分类！');
                return false;
            }

            if (data.field.auto_pass && auto_pass.data('exempt') < 1) {
                alt('免审次数不足,请使用普通投稿方式!', {icon: 5});
                return false;
            }
            // data.field.content = content;
            window.parent.$.showPreloader("数据提交中,上传图片文件可能需要一点时间...");
            $.ajax({
                type: "post",
                dataType: "json",
                url: api.tg,
                data: data.field,
                success: function (result) {
                    result.msg && alt(result.msg);
                    if (result.code === 1) {
                        var exempt = parseInt(auto_pass.data('exempt')) - 1;
                        auto_pass.data('exempt', exempt);
                        $("#exempt").html('exempt', exempt);
                    }
                    /*(result.code === 1) && form_reset(data);*/
                    (result.code === 1) && location.reload();
                },
                complete: function () {
                    window.parent.$.hidePreloader();
                }
            });
            return false;
        });

        function alt(msg) {
            if (window.parent.length > 0) {
                window.parent.$.alert(msg);
            } else {
                layer.open({type: 0, shadeClose: true, skin: 'atuikeLayerSkin1', content: msg, btn: ['我知道了']});
            }
        }

        //奖励开关
        form.on('switch(payopen)', function (data) {
            if (data.elem.checked) {
                $(".pays").show();
            } else {
                $(".pays").hide();
            }
        });
        //纯文章和附件
        form.on('radio(typeradio)', function (data) {
            if (data.value === "file") {
                $(".zips").show();
            } else {
                $(".zips").hide();
            }
        });
        //监听上传封面
        var uploadImg = $(".uploadImg");
        var uploadInst = upload.render({
            elem: uploadImg,
            auto: false,
            accept: 'image',
            acceptMime: 'image/*',
            choose: function (obj) {
                var imgDemo = uploadImg.find('img');
                obj.preview(function (index, file, result) {
                    $(".uploadImg>*").hide();
                    imgDemo.attr("src", result).show(500);
                    $("input[name=cover_img]").val(encodeURIComponent(result));
                });
            }
        });

        //监听上传附件
        var upyc;
        var pro = $(".jdt .layui-progress-bar");
        var fz = parseInt("200") * 1024;
        var upload_element = $(".zipupload");
        var softloadInst = upload.render({
            elem: upload_element,
            url: '/index/upload/upfile.html',
            auto: true,
            field: 'file_name',
            size: fz,
            accept: 'file',
            //acceptMime: 'application/zip,application/rar,video/mp4,application/vnd.android.package-archive',
            exts: 'zip|rar|mp4|apk',
            progress: function (value) {	 //上传进度回调 value进度值
                var bfb = value + "%";
                pro.width(bfb);
                upload_element.css('color', '#00ca5f').html(bfb);
                if (value >= 100) {
                    $(".jdt").fadeOut(100);
                }
            },
            choose: function () {
                clearInterval(upyc);
                upyc = null;
                $(".zipupload").html("上传中..");
                $(".jdt").slideDown(300);
            },
            done: function (result) {
                alt(result.msg);
                if (result.code === 1) {
                    upload_element.css({
                        'border-color': '#00ca5f',
                        'color': '#00ca5f'
                    }).html("<i class='layui-icon layui-icon-ok-circle'></i>上传成功");
                    $('#down_link1').val(result.data.src);
                } else {
                    upload_element.css({
                        'border-color': '#e73f49',
                        'color': '#e73f49'
                    }).html("<i class='layui-icon layui-icon-face-surprised'></i>上传失败");
                }
                setTimeout(function () {
                    pro.width(0);
                }, 100)
            }
        });

        $(".zipupload").click(function(){
            if(!upyc){
                upyc = setInterval(function(){
                    if($(".layui-layer-content").text()=="选择的文件中包含不支持的格式"){
                        layer.closeAll();
                        alt("选择的文件中包含不支持的格式");
                        clearInterval(upyc);
                        upyc = null;
                    }
                },10);
            }
        })


        function form_reset(data) {
            var thisForm = $(data.elem).parents(".layui-form");
            thisForm.find(".layui-form-item").each(function (i, e) {
                $(e).find("input[type=text],input[type=hidden]").val("");
                $(e).find(".layui-form-onswitch").trigger("click");
                $(e).find(".uploadImg").find("img").hide().prev('div').fadeIn();
                $(e).find(".layui-form-radio").eq(0).trigger("click");
            });
            $("#myEditor").html("");
            thisForm[0].reset();
            form.render();
        }

        function verifyContent(obj) {
            obj.find("style").remove();
            obj.find("script").remove();
            obj.find("*").each(function (i, v) {
                var name_list = Array.from(v.attributes);
                if (name_list.length > 0) {
                    $.each(name_list, function (j, value) {
                        if (/^on.*?/.test(value.name)) {
                            v.removeAttribute(value.name);
                        }
                    });
                }
            })
        }

        //禁止图片被选中
        $("#myEditor").on("click", "p img", function (e) { /*如果提供了事件对象，则这是一个非IE浏览器*/
            if (e && e.stopPropagation) {
                e.stopPropagation();
                /*因此它支持W3C的stopPropagation()方法*/
            } else {
                return false;
                /*否则，我们需要使用IE的方式来取消事件冒泡*/
            }
        });
        //兼容苹果父级页面的兼容代码
        window.parent.$(".iframes").css("height", $("html").height());
    });
</script>
</body>
</html>